class JavaMethod(object):
    def __init__(self, modify, isInter, isAbstract, isStatic, returnType, methodName, body, throws=[], params={}):
        self.modify = modify
        self.isInter = isInter
        self.isAbstract = isAbstract
        self.isStatic = isStatic
        self.returnType = returnType
        self.methodName = methodName
        self.body = body
        self.throws = throws
        self.params = params

    def parseParams(self, params=None):
        if params is None or len(params.items()) == 0:
            return "()"
        paramsStr = '( '
        for key, value in params.items():
            paramsStr += " " + key + " " + value + ","
        return paramsStr[0:-1] + " )"

    def __str__(self):
        methodStr = self.modify
        if not self.isInter and not self.isAbstract:
            if self.isStatic:
                methodStr += " static "
        if self.isAbstract and not self.isInter:
            methodStr += " abstract "
        methodStr += " " + self.returnType + " " + self.methodName
        methodStr += " " + self.parseParams(self.params)
        if len(self.throws) > 0:
            methodStr += " throws "
            for ret in self.throws:
                methodStr += ret + ","
            methodStr = methodStr[0:-1]
        if self.isInter or self.isAbstract:
            return methodStr + ";"
        methodStr += "{\n" + self.body + "\n}"
        return methodStr

    __repr__ = __str__


if __name__ == '__main__':
    method = JavaMethod('public', False, True, True, 'void', 'testMethod', 'System.out.println(\"测试方法\")', [],
                        {'String': 'tester'})
    print(method)
